﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package GameMode {
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Classes.*;
    import com.greensock.*;
    import Display.*;
    import flash.text.*;
    import Engine.*;
    import com.zynga.skelly.util.*;

    public class GMObjMoveHelper extends Sprite {

        private static var m_waitingForDeactivate:Array = new Array();

        public var m_active:Boolean;
        public var m_gameObject:MapResource;
        public var m_movedObject:MapResource;
        public var m_displayObject:Sprite;
        private var m_textField1:TextField;
        private var m_textField2:TextField;
        private var m_textField3:TextField;
        private var m_icon:Bitmap;
        private var m_color:uint;

        public function GMObjMoveHelper(_arg1:ItemBonus, _arg2:MapResource, _arg3:Point, _arg4:TextFormat, _arg5:uint, _arg6:MapResource){
            var _local13:String;
            var _local14:int;
            this.m_displayObject = new Sprite();
            super();
            this.m_movedObject = _arg6;
            deactivatePending(_arg2);
            var _local7:Number = GMObjectMove.getSmallBonusTextSize();
            this.m_textField1 = new StrokeTextField(0, 0.4);
            this.m_textField3 = new StrokeTextField(0, 0.4);
            this.m_gameObject = _arg2;
            var _local8:TextField = this.m_textField1;
            var _local9:Number = ItemBonus.getBonusModifier(_arg2, _arg1.field);
            var _local10:int = Math.round(((_local9 - 1) * 100));
            var _local11 = "Bonus";
            if (_local10 < 0){
                _local11 = "decreaseBonus";
            };
            _local8.text = ZLoc.t("Main", _local11);
            _local8.border = false;
            _local8.embedFonts = true;
            _local8.autoSize = TextFieldAutoSize.LEFT;
            _arg4.size = _local7;
            _local8.setTextFormat(_arg4);
            var _local12:TextLineMetrics = _local8.getLineMetrics(0);
            _local8.x = (_arg3.x - (_local12.width / 2));
            _local8.y = (_arg3.y - ((_local12.height * 3) / 2));
            addChild(_local8);
            _local8 = this.m_textField3;
            if ((((_arg2 is Business)) && ((_arg1.name == "FranchiseAOE")))){
                _local13 = (((((ItemBonus.calcIndividualHQBonus((_arg2 as Business), this.m_movedObject) / 100) > 0)) ? "+" : "" + ItemBonus.calcIndividualHQBonus((_arg2 as Business), this.m_movedObject).toString()) + "%");
                _local14 = ItemBonus.calcIndividualHQBonus((_arg2 as Business), this.m_movedObject);
            } else {
                _local13 = ((((_arg1.percentModifier > 0)) ? "+" : "" + _arg1.percentModifier) + "%");
                _local14 = _arg1.percentModifier;
            };
            if (_local10 != _local14){
                _local13 = (_local13 + ((" (" + _local10) + "%)"));
            };
            _local8.text = _local13;
            _local8.border = false;
            _local8.embedFonts = true;
            _local8.autoSize = TextFieldAutoSize.LEFT;
            _arg4.size = _local7;
            _local8.setTextFormat(_arg4);
            _local12 = _local8.getLineMetrics(0);
            _local8.x = (_arg3.x - (_local12.width / 2));
            _local8.y = (_arg3.y - (_local12.height / 2));
            _local12 = _local8.getLineMetrics(0);
            addChild(_local8);
            GlobalEngine.viewport.overlayBase.addChild(this.m_displayObject);
            var _local15:Vector3 = this.m_gameObject.getSize();
            var _local16:Point = new Point(this.m_gameObject.getPosition().x, this.m_gameObject.getPosition().y);
            this.m_displayObject.graphics.clear();
            this.m_displayObject.graphics.lineStyle(3, _arg5, Constants.ALPHA_VALID_PLACEMENT);
            this.m_displayObject.graphics.beginFill(0, 0);
            this.drawTileArea(this.m_displayObject.graphics, _local16, _local15.x, _local15.y);
            this.m_displayObject.graphics.endFill();
            alpha = 0;
            this.activate();
        }
        public static function deactivatePending(_arg1:MapResource):void{
            var _local2:GMObjMoveHelper;
            for each (_local2 in m_waitingForDeactivate) {
                if (_local2.m_gameObject == _arg1){
                    _local2.deactivate();
                };
            };
        }
        public static function deactivateAllPending():void{
            var _local1:GMObjMoveHelper;
            for each (_local1 in m_waitingForDeactivate) {
                _local1.deactivate();
            };
            m_waitingForDeactivate.length = 0;
        }

        public function activate():void{
            GlobalEngine.viewport.uiBase.addChildAt(this, 0);
            TweenLite.to(this, GMObjectMove.BONUS_FADE_IN, {alpha:1});
            this.m_gameObject.setHighlightedSpecial(true, Constants.COLOR_HIGHLIGHT_BLUE, 4);
        }
        private function removeFromParent():void{
            var _local1:int = m_waitingForDeactivate.indexOf(this);
            if (_local1 >= 0){
                m_waitingForDeactivate.splice(_local1, 1);
            };
            if (parent != null){
                parent.removeChild(this);
            };
        }
        private function showYieldAndDeactivate2():void{
            TweenLite.to(this, GMObjectMove.BONUS_FADE_OUT, {
                alpha:0,
                delay:0.5,
                onComplete:this.removeFromParent
            });
        }
        public function showYieldAndDeactivate(_arg1:TextFormat):void{
            var textFmt:* = _arg1;
            var cont:* = Curry.curry(function (_arg1:Sprite):void{
                if (_arg1.parent != null){
                    _arg1.parent.removeChild(_arg1);
                };
            }, this);
            this.m_gameObject.setHighlighted(false);
            if (this.m_displayObject){
                GlobalEngine.viewport.overlayBase.removeChild(this.m_displayObject);
                this.m_displayObject = null;
            };
            TweenLite.to(this, GMObjectMove.BONUS_FADE_OUT, {
                x:this.x,
                immediateRender:false,
                onComplete:this.showYieldAndDeactivate2
            });
            m_waitingForDeactivate.push(this);
        }
        public function deactivate():void{
            var _local2:DisplayObjectContainer;
            this.m_gameObject.setHighlighted(false);
            if (this.m_displayObject){
                GlobalEngine.viewport.overlayBase.removeChild(this.m_displayObject);
                this.m_displayObject = null;
            };
            var _local1:int = m_waitingForDeactivate.indexOf(this);
            if (_local1 >= 0){
                m_waitingForDeactivate.splice(_local1, 1);
            };
            if (parent != null){
                _local2 = parent;
                _local2.removeChild(this);
                _local2.addChildAt(this, 0);
            };
            TweenLite.to(this, GMObjectMove.BONUS_FADE_OUT, {
                alpha:0,
                onComplete:this.removeFromParent
            });
        }
        public function drawTileArea(_arg1:Graphics, _arg2:Point, _arg3:Number, _arg4:Number):void{
            var _local5:Point = IsoMath.tilePosToPixelPos(_arg2.x, _arg2.y);
            var _local6:Vector2 = IsoMath.getPixelDeltaFromTileDelta(_arg3, 0);
            var _local7:Vector2 = IsoMath.getPixelDeltaFromTileDelta(0, _arg4);
            _arg1.moveTo(_local5.x, _local5.y);
            _arg1.lineTo((_local5.x + _local6.x), (_local5.y + _local6.y));
            _arg1.lineTo(((_local5.x + _local6.x) + _local7.x), ((_local5.y + _local6.y) + _local7.y));
            _arg1.lineTo((_local5.x + _local7.x), (_local5.y + _local7.y));
            _arg1.lineTo(_local5.x, _local5.y);
        }

    }
}//package GameMode 
